import Taro, { Component, Config } from '@tarojs/taro'
import { onError, Provider } from '@tarojs/mobx'
import '@tarojs/async-await'
import Index from './pages/home/index'
import counterStore from './store'

import './app.scss'

// Mobx 异常监听抛出异常
onError(error => {
  throw error
})

const store = {
  counterStore
}

const { setTabList } = counterStore

class App extends Component {
  config: Config = {
    pages: [
      'pages/home/index',
      'pages/member/index',
      'pages/member/login',
      'pages/error/index'
    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: '演示店铺',
      navigationBarTextStyle: 'black',
      backgroundColor: '#f7f7f7',
      enablePullDownRefresh: true
    },
    tabBar: {
      backgroundColor: '#fff',
      selectedColor: '#13C2C2',
      borderStyle: 'white',
      list: [
        {
          iconPath: 'assets/images/tabbar/home.png',
          selectedIconPath: 'assets/images/tabbar/home_active.png',
          pagePath: 'pages/home/index',
          text: '首页'
        },
        {
          iconPath: 'assets/images/tabbar/user.png',
          selectedIconPath: 'assets/images/tabbar/user_active.png',
          pagePath: 'pages/member/index',
          text: '会员中心'
        }
      ]
    },
    permission: {
      'scope.userLocation': {
        desc: '你的位置信息将用于购物地址使用'
      }
    }
  }

  componentDidMount() {
    setTabList(this.config.tabBar)
  }

  // 请勿修改此函数
  render () {
    return (
      <Provider store={store}>
        <Index />
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
